home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c / 734 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  3.4 KB

  1. Path: tbj.dec.com!diamond
  2. From: diamond@tbj.dec.com (Norman Diamond)
  3. Newsgroups: comp.std.c
  4. Subject: Re: It this portable?
  5. Date: 13 Apr 1996 01:08:59 GMT
  6. Organization: Digital Equipment Corporation Japan , Tokyo
  7. Message-ID: <4kmurb$f3a@usenet.pa.dec.com>
  8. References: <Dpp1tv.4Kq@ukpsshp1.serigate.philips.nl> <4kj9gn$6rm@engnews1.Eng.Sun.COM>
  9. Reply-To: diamond@tbj.dec.com (Norman Diamond)
  10. NNTP-Posting-Host: jit533.tbj.dec.com
  11.  
  12. In article <4kj9gn$6rm@engnews1.Eng.Sun.COM>, clamage@Eng.Sun.COM (Steve Clamage) writes:
  13. >In article 4Kq@ukpsshp1.serigate.philips.nl, baynes@ukpsshp1.serigate.philips.nl (Stephen Baynes) writes:
  14. >>Is this program [conforming to all possible conforming implementations]
  15. >>or is it going to give undefined behaviour?
  16. >>  #include <stdio.h>
  17. >>  #include <limits.h>
  18. >>  int main( void )
  19. >>  {
  20. >>      printf( "%d", UINT_MAX );
  21. >>      return 0;
  22. >>  }
  23. >>My vote is for undefined, but can anyone construct an argument based on
  24. >>the represention of integers that makes it implmentation defined?
  25.  
  26. >The example passes an unsigned int to printf and tells printf to
  27. >interpret the value as a signed int.
  28.  
  29. Exactly.  It does not say to convert the unsigned int.  Actually, not
  30. quite exactly.  Although an implementation storing type tags would be
  31. contrary to the traditional spirit of C, it would not violate the
  32. standard.  The example tells such an implementation to check whether
  33. the standard's rules gave the expression UINT_MAX the type int.
  34.  
  35. >The Standard's section on types says that signed int and unsigned int
  36. >have the same size (including sign information) and alignment, and a
  37. >footnote clarifies the intention to allow interchangeability as
  38. >function parameters and return values.
  39.  
  40. Exactly.  The standard makes some rules that don't really accomplish
  41. much but which provide encouragement for implementations to provide some
  42. nice extensions.  The footnote clarifies that the committee's intention
  43. was to encourage implementations to provide some nice extensions.  And
  44. if I'm not mistaken, the committee already responded to a defect report
  45. by reaffirming that their intention was to encourage implementations to
  46. provide some nice extensions, but that implementations are not forced to
  47. provide this interchangeability.
  48.  
  49. >The section on conversions says the result of converting an unsigned int
  50. >to a signed int is implementation-defined if the value of the unsigned
  51. >int is not representable as a signed int.
  52.  
  53. Exactly.  It does not say anything about the result of type punning
  54. without conversion.
  55.  
  56. >The example has no undefined behavior, but it does have implementation-
  57. >defined behavior.
  58.  
  59. Obviously I disagree.  The example has undefined behavior, but can have
  60. implementation defined behavior by implementation extension.
  61.  
  62. >Pragmatically, most popular machines are straight 2's complement with no
  63. >overflow checking,
  64.  
  65. Pragmatically, yes.
  66.  
  67. >so you will probably get the same result across a
  68. >variety of compilers and platforms.
  69.  
  70. Pragmatically, no.  As incompetent as the original advertiser was, their
  71. intention was clear:  they thought the result would depend on word length.
  72. --
  73.  <<  If this were the company's opinion, I would not be allowed to post it.  >>
  74. "I paid money for this car, I pay taxes for vehicle registration and a driver's
  75. license, so I can drive in any lane I want, and no innocent victim gets to call
  76. the cops just 'cause the lane's not goin' the same direction as me" - J Spammer
  77.